import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';

// https://vite.dev/config/
export default defineConfig(({mode}) => {
  const root = process.cwd();
  const env = loadEnv(mode, root);

  if(env.VITE_PARAM === 'dev') {
    console.error("-----------------------------------")
    console.error("----------- 测试环境 ---------------")
    console.error(`----------- ${env.VITE_BASE_URL} ---------------`)
    console.error("----------------------------------")
  }else{
    console.error("----------------------------------")
    console.error("----------- 正式环境 ---------------")
    console.error(`----------- ${env.VITE_BASE_URL} ---------------`)
    console.error("-----------------------------------")
  }

  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),// 设置 `@` 指向 `src` 目录
        "@assets": path.resolve(__dirname, "./src/assets"),
        "@components": path.resolve(__dirname, "./src/components"),
      },
    },
    css: {
      preprocessorOptions: {
        // 配置全局共享变量scss
        scss: {
          additionalData: '@use "@/style/mixin.scss" as __mixin;',
        }
      }
    },
    build: {
      rollupOptions: {
        output: {
          chunkFileNames: `js/[name]-[hash]-${new Date().getTime()}.js`,
          entryFileNames: `js/[name]-[hash]-${new Date().getTime()}.js`,
          assetFileNames: `[ext]/[name]-[hash]-${new Date().getTime()}.[ext]`
        }
      }
    }
  }
})
